package com.xiyu.service.repository.files.certificate;

import com.xiyu.service.model.files.certificate.FilesRealEstateFetcher;
import com.xiyu.service.model.office.area.OfficeAreaFetcher;
import com.xiyu.service.vo.files.realEstate.RealEstatePageQueryInput;
import com.xiyu.service.model.files.certificate.FilesRealEstate;
import com.xiyu.service.model.files.certificate.FilesRealEstateTable;
import org.babyfish.jimmer.spring.repository.JRepository;
import org.babyfish.jimmer.Page;

public interface FilesRealEstateRepository extends JRepository<FilesRealEstate, Long> {
    FilesRealEstateTable filesRealEstateTable = FilesRealEstateTable.$;

    default Page<FilesRealEstate> pageQuery(RealEstatePageQueryInput inputVO){
        return
            sql().createQuery(filesRealEstateTable)
                    .where(filesRealEstateTable.obligee().likeIf(inputVO.getObligee()))
                    .where(filesRealEstateTable.realEstateNo().likeIf(inputVO.getRealEstateNo()))
                    .where(filesRealEstateTable.fileNo().likeIf(inputVO.getFileNo()))
                    .where(filesRealEstateTable.location().likeIf(inputVO.getLocation()))
                    .where(filesRealEstateTable.remark().likeIf(inputVO.getRemark()))
                    .where(filesRealEstateTable.area().name().likeIf(inputVO.getAreaName()))
                    .orderBy(filesRealEstateTable.id().desc())
                    .select(filesRealEstateTable.fetch(FilesRealEstateFetcher.$.allTableFields().area(OfficeAreaFetcher.$.allTableFields())))
                    .fetchPage(inputVO.getPageNo() - 1, inputVO.getPageSize());

    }


}